<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="">
        <el-select v-model="queryParams.railwayName" placeholder="线名" clearable style="width: 140px">
          <el-option v-for="dict in railwayNameobj" :key="dict.railwayName" :label="dict.railwayName" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="queryParams.tunnelId" placeholder="隧道号" clearable style="width: 140px"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="queryParams.segmentUnitCode" placeholder="节段单元编码" clearable style="width: 140px"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="queryParams.segmentStartingMileageStr" placeholder="节段起点里程" clearable style="width: 140px"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="queryParams.segmentDestinationMileageStr" placeholder="节段终点里程" clearable style="width: 140px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList" style="width: 90px">查询</el-button>
        <el-button @click="resetQuery" style="width: 90px">重置</el-button>
        <el-button type="primary" @click="handleQuery" style="width: 90px">导出</el-button>
        <el-button type="primary" @click="handleAdd" style="width: 90px">新增</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格数据 -->
    <el-table :key="Math.random()" v-loading="loading" :data="railList" height="62vh" border @selection-change="selectiontab">
      <el-table-column type="selection" label="全选" width="50" />
      <el-table-column label="序号" type="index" width="80" />
      <el-table-column label="线名" prop="railwayName" min-width="80" />
      <el-table-column label="隧道号" prop="tunnelCode" min-width="80" />
      <el-table-column label="隧道名" prop="tunnelName" min-width="80" />
      <el-table-column label="节段单元编码" prop="segmentUnitCode" min-width="80" />
      <el-table-column label="节段起点里程" prop="segmentStartingMileageStr" min-width="80" />
      <el-table-column label="节段终点里程" prop="segmentDestinationMileageStr" min-width="80" />
      <el-table-column label="基底类型" prop="baseTypeId" min-width="80" />
      <el-table-column label="隧底结构类型" prop="tunnelStructureType" min-width="80" />
      <el-table-column label="底板材质" prop="baseplateTexture" min-width="80" />
      <el-table-column label="底板厚度" prop="baseplateThickness" min-width="80" />
      <el-table-column label="仰拱材质" prop="inflectedArchTexture" min-width="80" />
      <el-table-column label="仰拱曲率" prop="inflectedArchCurvature" min-width="80" />
      <el-table-column label="仰拱厚度" prop="inflectedArchThickness" min-width="80" />
      <el-table-column label="仰拱填充材质" prop="inflectedArchFillTexture" min-width="80" />
      <el-table-column label="仰拱填充中心厚度" prop="inflectedArchFillThickness" min-width="80" />
      <el-table-column label="直接数据" min-width="110">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary" @click="parameter(scope.row)">参数</el-button>
            <el-button link type="primary" @click="meansFun(scope.row)">资料</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="关联数据" min-width="210">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary">作业履历</el-button>
            <el-button link type="primary">设备问题</el-button>
            <el-button link type="primary">业财</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="80">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary" @click="handDelete(scope.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" v-model="open" width="1300px" append-to-body>
      <el-form ref="userRef" :model="form" :rules="rules" label-width="80px" :inline="true">
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">位置</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="单位名称" prop="unitId">
              <el-select filterable clearable style="width: 180px" v-model="form.unitId" placeholder="请选择">
                <el-option v-for="dict in unitNameobj" :key="dict.id" :label="dict.unitName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="线名" prop="railwayId">
              <el-select filterable clearable style="width: 180px" v-model="form.railwayId" placeholder="请选择" @change="getsdhData">
                <el-option v-for="dict in railwayNameobj" :key="dict.id" :label="dict.railwayName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="隧道号" prop="tunnelId">
              <el-select filterable clearable style="width: 180px" v-model="form.tunnelId" placeholder="请选择" @change="getsdName">
                <el-option v-for="dict in tunnelCodeList" :key="dict.id" :label="dict.tunnelCode" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="隧道名" prop="tunnelName">
              <el-input disabled v-model="form.tunnelName" placeholder="请输入隧道名" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="节段单元编码" prop="segmentUnitId">
              <el-select filterable clearable style="width: 180px" v-model="form.segmentUnitId" placeholder="请选择" @change="getSegmentUnit">
                <el-option v-for="dict in segmentUnitList" :key="dict.id" :label="dict.segmentUnitCode" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="节段起点里程" prop="segmentStartingMileage">
              <el-input disabled v-model="form.segmentStartingMileage" placeholder="请输入节段起点里程" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="节段终点里程" prop="segmentDestinationMileage">
              <el-input disabled v-model="form.segmentDestinationMileage" placeholder="请输入节段终点里程" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">特性</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="基底类型" prop="baseTypeId">
              <el-select filterable clearable style="width: 180px" v-model="form.baseTypeId" placeholder="请选择">
                <el-option v-for="dict in baseTypeIdList" :key="dict.id" :label="dict.propertyName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="轨下衬砌图号" prop="segmentRailLiningNum">
              <el-input v-model="form.segmentRailLiningNum" placeholder="请输入轨下衬砌图号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="隧底结构类型" prop="tunnelStructureTypeId">
              <el-select filterable clearable style="width: 180px" v-model="form.tunnelStructureTypeId" placeholder="请选择" @change="getrules">
                <el-option v-for="dict in tunnelStructureTypeIdList" :key="dict" :label="dict.propertyName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="底板材质" prop="baseplateTextureId">
              <el-select filterable clearable style="width: 180px" v-model="form.baseplateTextureId" placeholder="请选择">
                <el-option v-for="dict in baseplateTextureIdList" :key="dict.id" :label="dict.propertyName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="底板厚度" prop="baseplateThickness">
              <el-input type="number" v-model="form.baseplateThickness" placeholder="请输入底板厚度" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="仰拱材质" prop="inflectedArchTextureId">
              <el-select filterable clearable style="width: 180px" v-model="form.inflectedArchTextureId" placeholder="请选择">
                <el-option v-for="dict in inflectedArchTextureIdList" :key="dict.id" :label="dict.propertyName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="仰拱曲率" prop="inflectedArchCurvature">
              <el-input type="number" v-model="form.inflectedArchCurvature" placeholder="请输入仰拱曲率" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="仰拱厚度" prop="inflectedArchThickness">
              <el-input type="number" v-model="form.inflectedArchThickness" placeholder="请输入仰拱厚度" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="仰拱填充材质" prop="inflectedArchFillTextureId">
              <el-select filterable clearable style="width: 180px" v-model="form.inflectedArchFillTextureId" placeholder="请选择">
                <el-option v-for="dict in inflectedArchFillTextureIdList" :key="dict.id" :label="dict.propertyName" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="仰拱填充中心厚度" prop="inflectedArchFillThickness">
              <el-input type="number" v-model="form.inflectedArchFillThickness" placeholder="请输入仰拱填充中心厚度" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">健康值</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="健康值" prop="healthIndex">
              <el-input v-model="form.healthIndex" placeholder="请输入健康值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="隐患等级" prop="hiddenDangerLevel">
              <el-input v-model="form.hiddenDangerLevel" placeholder="请输入隐患等级" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存在问题" prop="existingProblem">
              <el-input v-model="form.existingProblem" placeholder="请输入存在问题" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="病害整治情况" prop="diseaseControlSituation">
              <el-input v-model="form.diseaseControlSituation" placeholder="请输入病害整治情况" /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="病害整治年份" prop="yearOfDiseaseControl">
              <el-input v-model="form.yearOfDiseaseControl" placeholder="请输入病害整治年份" /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="设备使用频率" prop="equipmentUsageFrequency">
              <el-input v-model="form.equipmentUsageFrequency" placeholder="请输入设备使用频率" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备综合效率(OEE)" prop="overallEquipmentEfficiency">
              <el-input v-model="form.overallEquipmentEfficiency" placeholder="请输入设备综合效率(OEE)" /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="平均无故障工作时间(MTTF)" prop="meanTimeToFailure">
              <el-input v-model="form.meanTimeToFailure" placeholder="请输入平均无故障工作时间(MTTF)" /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="平均修复时间(MTTR)" prop="meanTimeToRepair">
              <el-input v-model="form.meanTimeToRepair" placeholder="请输入平均修复时间(MTTR)" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">管理</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="区段" prop="sector">
              <el-input v-model="form.sector" placeholder="请输入区段" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工区" prop="workArea">
              <el-input v-model="form.workArea" placeholder="请输入工区" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员" prop="personnel">
              <el-input v-model="form.personnel" placeholder="请输入人员" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="包保责任人" prop="personInCharge">
              <el-input v-model="form.personInCharge" placeholder="请输入包保责任人" /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="comment">
              <el-input v-model="form.comment" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="divflex" v-if="parameterShow">
        <span class="leftx"></span>
        <span class="mainz">修改历史</span>
        <span class="rightx"></span>
      </div>
      <el-table :key="Math.random()" :data="allBridgeChangeData" border height="300px" v-if="parameterShow">
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column label="指标名" prop="property" min-width="80"></el-table-column>
        <el-table-column label="变更前指标值" prop="oldValue" min-width="80"></el-table-column>
        <el-table-column label="变更后指标值" prop="newValue" min-width="80"></el-table-column>
        <el-table-column label="变更时间" prop="createTime" min-width="80"></el-table-column>
        <el-table-column label="操作用户名" prop="user" min-width="80"></el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog draggable title="资料" v-model="meansopen" width="1300px" append-to-body @close="closefun">
      <means :forma="formam" parentName="隧底结构" v-if="meansopen"></means>
    </el-dialog>
  </div>
</template>

<script setup name="Bridge">
import means from "@/components/railmodle/means.vue";
import { useContent } from "@/mixin/index.js";
const { meansopen, meansFun, formam, closefun } = useContent();
import {
  selectManTunnelSegmentStructureList,
  addinsertManTunnelSegmentStructure,
  editManTunnelSegmentStructure,
  deleteManTunnelSegmentStructureById,
  selectManTunnelSegmentStructureById,
  getselectManTunnelEditRecordList,
  selectManTunnelOverviewList,
  selectManTunnelSegmentUnitList,
  getSelectListApi,
} from "@/api/main/bridge.js";
import { selectManBasicUnitListapi, selectManBasicRailwayListapi, selectManBasicprogressTypeListapi } from "@/api/main/api.js";
import { ElMessage } from "element-plus";
import { reactive, ref, toRefs } from "vue";
const { proxy } = getCurrentInstance();
const title = ref("新增");
const loading = ref(true);
const open = ref(false);

const parameterShow = ref(false);

defineExpose({ getList });
const emit = defineEmits(["parentCount"]);

const data = reactive({
  faultForm: {
    railwayName: "",
    tabledata: [],
  },
  railList: [],
  selecttabList: [],
  //单位名称列表数据
  unitNameobj: [],
  //线名数据列表
  railwayNameobj: [],
  // 隧道号
  tunnelCodeList: [],
  // 节段单元编码
  segmentUnitList: [],
  // 基底类型
  baseTypeIdList: [],
  // 底板材质
  baseplateTextureIdList: [],
  // 仰拱材质
  inflectedArchTextureIdList: [],
  tunnelStructureTypeIdList: [],
  // 仰拱填充材质
  inflectedArchFillTextureIdList: [],
  form: {},
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    railwayName: "",
    tunnelId: "",
    segmentUnitCode: "",
    segmentStartingMileageStr: "",
    segmentDestinationMileageStr: "",
  },
  rules: {
    unitId: [{ required: true, message: "单位名称不能为空", trigger: ["blur", "change"] }],
    railwayId: [{ required: true, message: "线名不能为空", trigger: ["blur", "change"] }],
    tunnelId: [{ required: true, message: "隧道号不能为空", trigger: ["blur", "change"] }],
    segmentUnitId: [{ required: true, message: "节段单元编码不能为空", trigger: ["blur", "change"] }],
    tunnelStructureTypeId: [{ required: true, message: "隧底结构类型不能为空", trigger: ["blur", "change"] }],
  },
  allBridgeChangeData: [],
  economyTableData: [],
  ledgerTabledata: [],
});

const {
  faultForm,
  queryParams,
  railList,
  selecttabList,
  form,
  rules,
  unitNameobj,
  railwayNameobj,
  tunnelCodeList,
  baseTypeIdList,
  baseplateTextureIdList,
  tunnelStructureTypeIdList,
  inflectedArchTextureIdList,
  inflectedArchFillTextureIdList,
  segmentUnitList,
  allBridgeChangeData,
  economyTableData,
  ledgerTabledata,
} = toRefs(data);

const pageNumparent = ref(undefined);
const pageSizeparent = ref(undefined);

function init() {
  getLineDataList();
  getUnitDataList();
  getsdhData();
  getData();
  getList();
}
init();
/** 查询列表 */
function getList(pageNum, pageSize) {
  loading.value = true;
  if (pageNum != undefined || pageSize != undefined) {
    pageNumparent.value = pageNum;
    pageSizeparent.value = pageSize;
    queryParams.value.pageNum = pageNum == undefined ? 1 : pageNum;
    queryParams.value.pageSize = pageSize == undefined ? 10 : pageSize;
  } else {
    queryParams.value.pageNum = pageNumparent.value == undefined ? "1" : pageNumparent.value;
    queryParams.value.pageSize = pageSizeparent.value == undefined ? "10" : pageSizeparent.value;
  }
  selectManTunnelSegmentStructureList({
    pageNumber: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    railwayId: queryParams.value.railwayName,
    tunnelCode: queryParams.value.tunnelId,
    segmentUnitCode: queryParams.value.segmentUnitCode,
    segmentStartingMileage: queryParams.value.segmentStartingMileageStr,
    segmentDestinationMileage: queryParams.value.segmentDestinationMileageStr,
  }).then((res) => {
    if (res.code == 200) {
      data.railList = res.data;
    }
    loading.value = false;
    emit("parentCount", res.count);
  });
}
/** 查询基础数据-线名数据列表 */
function getLineDataList() {
  selectManBasicRailwayListapi().then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
      console.log(railwayNameobj.value);
    }
  });
}
/** 查询基础数据-单位数据列表 */
function getUnitDataList() {
  selectManBasicUnitListapi().then((res) => {
    if (res.code == 200) {
      unitNameobj.value = res.data;
      console.log(unitNameobj.value);
    }
  });
}
/** 查询-隧道号数据列表 */
function getsdhData() {
  selectManTunnelOverviewList({
    railwayId: form.value.railwayId,
  }).then((res) => {
    if (res.code == 200) {
      tunnelCodeList.value = res.data;
      form.value.tunnelId = "";
      form.value.tunnelName = "";
      form.value.segmentUnitId = "";
      form.value.segmentStartingMileage = "";
      form.value.segmentDestinationMileage = "";
      form.value.segmentRailLiningNum = "";
    }
  });
}
/** 查询-数据列表 */
function getData() {
  getSelectListApi({ propertyType: "基底类型" }).then((res) => {
    if (res.code == 200) {
      baseTypeIdList.value = res.data;
    }
  });
  getSelectListApi({ propertyType: "底板材质" }).then((res) => {
    if (res.code == 200) {
      baseplateTextureIdList.value = res.data;
    }
  });
  getSelectListApi({ propertyType: "隧底结构类型" }).then((res) => {
    if (res.code == 200) {
      tunnelStructureTypeIdList.value = res.data;
    }
  });
  getSelectListApi({ propertyType: "仰拱材质" }).then((res) => {
    if (res.code == 200) {
      inflectedArchTextureIdList.value = res.data;
    }
  });
  getSelectListApi({ propertyType: "仰拱填充材质" }).then((res) => {
    if (res.code == 200) {
      inflectedArchFillTextureIdList.value = res.data;
    }
  });
}

/* 删除单行数据 */
function handDelete(row) {
  deleteManTunnelSegmentStructureById({ id: row }).then((res) => {
    if (res.code == 200) {
      proxy.$modal.msgSuccess("删除成功");
      getList();
    }
  });
}

/** 重置操作表单 */
function reset() {
  form.value = {
    id: "",
    unitId: "",
    railwayId: "",
    tunnelId: "",
    tunnelName: "",
    segmentUnitId: "",
    segmentStartingMileage: "",
    segmentDestinationMileage: "",
    baseTypeId: "",
    segmentRailLiningNum: "",
    tunnelStructureTypeId: "",
    baseplateTextureId: "",
    baseplateThickness: "",
    inflectedArchTextureId: "",
    inflectedArchCurvature: "",
    inflectedArchThickness: "",
    inflectedArchFillTextureId: "",
    inflectedArchFillThickness: "",
    healthIndex: "",
    hiddenDangerLevel: "",
    existingProblem: "",
    diseaseControlSituation: "",
    yearOfDiseaseControl: "",
    equipmentUsageFrequency: "",
    overallEquipmentEfficiency: "",
    meanTimeToFailure: "",
    meanTimeToRepair: "",
    sector: "",
    workArea: "",
    personnel: "",
    personInCharge: "",
    comment: "",
  };
  proxy.resetForm("userRef");
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "新增";
  parameterShow.value = false;
  tunnelCodeList.value = [];
  segmentUnitList.value = [];
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["userRef"].validate((valid) => {
    if (valid) {
      //单位名称列表数据
      unitNameobj.value.forEach((item) => {
        if (form.value.unitId == item.id) {
          form.value.unitName = item.unitName;
        }
      });
      //线名数据列表
      railwayNameobj.value.forEach((item) => {
        if (form.value.railwayId == item.id) {
          form.value.railwayName = item.railwayName;
        }
      });
      // 节段单元编码
      segmentUnitList.value.forEach((item) => {
        if (form.value.segmentUnitId == item.id) {
          form.value.segmentUnitCode = item.segmentUnitCode;
        }
      });
      // 基底类型
      baseTypeIdList.value.forEach((item) => {
        if (form.value.baseTypeId == item.id) {
          form.value.baseType = item.propertyName;
        }
      });
      // 底板材质
      baseplateTextureIdList.value.forEach((item) => {
        if (form.value.baseplateTextureId == item.id) {
          form.value.baseplateTexture = item.propertyName;
        }
      });
      // 仰拱材质
      inflectedArchTextureIdList.value.forEach((item) => {
        if (form.value.inflectedArchTextureId == item.id) {
          form.value.inflectedArchTexture = item.propertyName;
        }
      });
      // 隧底结构类型
      tunnelStructureTypeIdList.value.forEach((item) => {
        if (form.value.tunnelStructureTypeId == item.id) {
          form.value.tunnelStructureType = item.propertyName;
        }
      });
      // 仰拱填充材质
      inflectedArchFillTextureIdList.value.forEach((item) => {
        if (form.value.inflectedArchFillTextureId == item.id) {
          form.value.inflectedArchFillTexture = item.propertyName;
        }
      });
      if (form.value.id) {
        editManTunnelSegmentStructure(form.value).then((res) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addinsertManTunnelSegmentStructure(form.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
function selectiontab(row) {
  selecttabList.value = row;
}
// 导出
function handleQuery() {
  const arrid = [];
  for (let i = 0; i < selecttabList.value.length; i++) {
    arrid.push(selecttabList.value[i].id);
  }
  proxy.download1("/facility-manage/structure/exportExcel", arrid, `隧底结构${new Date().getTime()}.xlsx`);
}
//重置
function resetQuery() {
  queryParams.value = {
    railwayName: "",
    tunnelId: "",
    segmentUnitCode: "",
    segmentStartingMileageStr: "",
    segmentDestinationMileageStr: "",
  };
  getList();
}
// 查看参数
function parameter(rows) {
  selectManTunnelSegmentStructureById({
    id: rows.id,
  }).then((res) => {
    form.value = res.data;
    getselectManTunnelEditRecordList({
      tunnelId: rows.id,
    }).then((res1) => {
      getrules();
      allBridgeChangeData.value = res1.data;
      title.value = "参数";
      open.value = true;
      parameterShow.value = true;
    });
  });
}
// 获取隧道名
function getsdName(bridgeName) {
  form.value.tunnelName = "";
  form.value.segmentUnitId = "";
  form.value.segmentStartingMileage = "";
  form.value.segmentDestinationMileage = "";
  form.value.segmentRailLiningNum = "";
  if (form.value.railwayId) {
    tunnelCodeList.value.forEach((item) => {
      if (form.value.tunnelId == item.id) {
        form.value.tunnelName = item.tunnelName;
      }
    });
    selectManTunnelSegmentUnitList({
      tunnelId: form.value.tunnelId,
    }).then((res) => {
      if (res.code == 200) {
        segmentUnitList.value = res.data;
      }
    });
  } else {
    ElMessage.error("请先选择线名");
    form.value.tunnelId = "";
  }
}
// 获取节段单元信息
function getSegmentUnit() {
  if (form.value.tunnelId) {
    form.value.segmentStartingMileage = "";
    form.value.segmentDestinationMileage = "";
    form.value.segmentRailLiningNum = "";
    segmentUnitList.value.forEach((item) => {
      if (form.value.segmentUnitId == item.id) {
        form.value.segmentStartingMileage = item.segmentStartingMileage;
        form.value.segmentDestinationMileage = item.segmentDestinationMileage;
        form.value.segmentRailLiningNum = item.segmentRailLiningNum;
      }
    });
  } else {
    ElMessage.error("请先选择隧道名");
    form.value.segmentUnitId = "";
  }
}
// 修改规则
function getrules() {
  let names = "";
  tunnelStructureTypeIdList.value.forEach((item) => {
    if (item.id == form.value.tunnelStructureTypeId) {
      names = item.propertyName;
    }
  });
  rules.value = {
    unitId: [{ required: false, message: "单位名称不能为空", trigger: ["blur", "change"] }],
    railwayId: [{ required: false, message: "线名不能为空", trigger: ["blur", "change"] }],
    tunnelId: [{ required: false, message: "隧道号不能为空", trigger: ["blur", "change"] }],
    segmentUnitId: [{ required: false, message: "节段单元编码不能为空", trigger: ["blur", "change"] }],
    tunnelStructureTypeId: [{ required: false, message: "隧底结构类型不能为空", trigger: ["blur", "change"] }],
    baseplateTextureId: [{ required: false, message: "底板材质不能为空", trigger: ["blur", "change"] }],
    baseplateThickness: [{ required: false, message: "底板厚度不能为空", trigger: ["blur", "change"] }],
    inflectedArchTextureId: [{ required: false, message: "仰拱材质不能为空", trigger: ["blur", "change"] }],
    inflectedArchCurvature: [{ required: false, message: "仰拱曲率不能为空", trigger: ["blur", "change"] }],
    inflectedArchThickness: [{ required: false, message: "仰拱厚度不能为空", trigger: ["blur", "change"] }],
    inflectedArchFillTextureId: [{ required: false, message: "仰拱填充材质不能为空", trigger: ["blur", "change"] }],
    inflectedArchFillThickness: [{ required: false, message: "仰拱填充中心厚度不能为空", trigger: ["blur", "change"] }],
  };

  console.log(rules.value);
  if (names == "底板") {
    let arr = ["unitId", "railwayId", "tunnelId", "segmentUnitId", "tunnelStructureTypeId", "baseplateTextureId", "baseplateThickness"];
    for (const key in rules.value) {
      for (let i = 0; i < arr.length; i++) {
        if (key == arr[i]) {
          rules.value[key][0].required = true;
        }
      }
    }
  } else if (names == "仰拱") {
    let arr = [
      "unitId",
      "railwayId",
      "tunnelId",
      "segmentUnitId",
      "tunnelStructureTypeId",
      "inflectedArchTextureId",
      "inflectedArchCurvature",
      "inflectedArchThickness",
      "inflectedArchFillTextureId",
      "inflectedArchFillThickness",
    ];
    for (const key in rules.value) {
      for (let i = 0; i < arr.length; i++) {
        if (key == arr[i]) {
          rules.value[key][0].required = true;
        }
      }
    }
  } else {
    let arr = ["unitId", "railwayId", "tunnelId", "segmentUnitId", "tunnelStructureTypeId"];
    for (const key in rules.value) {
      for (let i = 0; i < arr.length; i++) {
        if (key == arr[i]) {
          rules.value[key][0].required = true;
        }
      }
    }
  }
}
// 设备
function equipmentproblem() {}
// 业财
function businessFinance() {}
</script>

<style scoped lang="scss">
.divflex {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .leftx {
    width: 45%;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #e8e8e8;
    margin-top: 3px;
  }

  .mainz {
    font-weight: 400;
    font-style: normal;
    font-size: 16px;
    line-height: 24px;
  }

  .rightx {
    width: 45%;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #e8e8e8;
    margin-top: 3px;
  }
}

.buttontext {
  .el-button:hover {
    text-decoration: line-through !important;
  }
}

.el-form--inline .el-form-item.formitemcla {
  margin-right: 5px !important;
}
</style>
